<template>
  <div>
    <input type="text" placeholder="账号" v-model="account" />
    <br />
    <input type="password" placeholder="密码" v-model="password" />
    <br />
    <button @click="login">登录</button>
  </div>
</template>

<script>
export default {
  name: "Vue2FxhLogin",
  data() {
    return {
      account: "",
      password: "",
    };
  },
  methods: {
    login() {
      this.$axios
        .post("https://apif.java.crmeb.net/api/front/login", {
          account: this.account,
          password: this.password,
        })
        .then(({ data }) => {
          console.log(data);
          if (data.code !== 200) {
            alert(data.message);
            return;
          }
          localStorage.setItem("token", data.data.token);
          const destPath = this.$route.query.redirect;
          if (destPath) this.$router.replace(destPath);
          else this.$router.replace("/");
        });
    },
  },
};
</script>

<style lang="scss" scoped></style>
